home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / amiexpress / source / utils / zerobyte / zerobyte.c next >
Encoding:
C/C++ Source or Header  |  1992-12-26  |  1.5 KB  |  78 lines

  1. #include <exec/exec.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. char FileName[200];
  5. void sr(char *s);
  6. main(int argc,char *argv[])
  7. {
  8.    FILE *fi,*fo;
  9.    long count=0L;
  10.    char temp[200];
  11.    if(argc<2)
  12.    {
  13.      printf("ZEROBYTE version 1.2, written by Joseph Hodge\n");
  14.      printf("Usage: ZEROBYTE <filename> [-L]\n");
  15.      printf("   ie: ZEROBYTE FileName\n");
  16.      printf("   ie: ZEROBYTE FileList -L\n");
  17.      printf("\n");
  18.      exit(0);
  19.    }
  20.  
  21.    
  22.    strcpy(FileName,argv[1]);
  23.    sr(FileName);
  24.    if(argc==3)
  25.    {
  26.    fi=fopen(FileName,"r");
  27.    if(fi==NULL)
  28.    {
  29.       printf("File %d not found or is in use\n");
  30.       printf("\n");
  31.       exit(0);
  32.    }
  33.    while(fgets(temp,80,fi)!=NULL)
  34.    {
  35.      sprintf(FileName,"RAM:%s",temp);
  36.      sr(FileName);
  37.      fo=fopen(FileName,"w");
  38.      if(fo==NULL)
  39.      {
  40.        printf("Error, can't create file %s\n",FileName);
  41.      }else
  42.      {
  43.      fclose(fo); count +=1L; }
  44.    }
  45.    fclose(fi);
  46.    printf("\n");
  47.    printf("%d ZEROBYTE files created\n",count);
  48.    printf("\n");
  49.   }
  50.   else
  51.   {
  52.     strcpy(temp,FileName);
  53.     strcpy(FileName,FilePart(temp));
  54.     sprintf(temp,"RAM:%s",FileName);
  55.     while(1)
  56.     {
  57.       fi=fopen(temp,"r");
  58.       if(fi) { fclose(fi);strcat(temp,"_");
  59.                if(strlen(temp)>30) { printf("ZEROBYTE Error on File %s\n",temp); exit(0); } continue; }
  60.       break;
  61.     }  
  62.     fi=fopen(temp,"w");
  63.     fclose(fi);
  64.     printf("ZEROBYTE of %s complete\n",temp);
  65.   }
  66.   exit(0);
  67. }
  68.  
  69. void sr(char *s)
  70. {
  71.   register int i;
  72.   i=strlen(s)-1;
  73.   while(i>-1)
  74.   {
  75.     if(*(s+i)<=32) *(s+i)=0; else break;
  76.     i--;
  77.   }
  78. }